package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.vo.OrderReportStatisticVO;
import com.yxx.medicinepojo.vo.SalesTop10ReportStatisticVO;
import com.yxx.medicinepojo.vo.TurnoverReportStatisticVO;
import com.yxx.medicinepojo.vo.UserReportStatisticVO;
import com.yxx.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

/**
 * @author yuxiangxun
 * @date 2024/9/17
 * @apiNote
 */
@Slf4j
@RestController
@Api(tags = "数据统计相关接口")
@RequestMapping("/admin/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 营业额统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计")
    public ResponseResult<TurnoverReportStatisticVO> turnoverReportStatistic(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
        TurnoverReportStatisticVO turnoverReportStatisticVO = reportService.getTurnoverStatistics(begin,end);
        return ResponseResult.success(turnoverReportStatisticVO);
    }

    /**
     * 用户统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/userStatistics")
    @ApiOperation("用户统计")
    public ResponseResult<UserReportStatisticVO> userReportStatistic(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        UserReportStatisticVO userReportStatisticVO = reportService.getUserStatistics(begin,end);
        return ResponseResult.success(userReportStatisticVO);
    }

    /**
     * 销量排名top10
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/top10")
    @ApiOperation("销量排名top10")
    public ResponseResult<SalesTop10ReportStatisticVO> top10ReportStatistic(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        SalesTop10ReportStatisticVO salesTop10ReportStatisticVO = reportService.getTop10Statistics(begin,end);
        return ResponseResult.success(salesTop10ReportStatisticVO);
    }

    /**
     * 订单统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ordersStatistics")
    @ApiOperation("订单统计")
    public ResponseResult<OrderReportStatisticVO> ordersReprotStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        OrderReportStatisticVO orderReportStatisticVO = reportService.getOrdersReportStatistics(begin,end);
        return ResponseResult.success(orderReportStatisticVO);
    }

    /**
     * 中西药购销运营数据表导出
     * @param response
     */
    @GetMapping("/export")
    @ApiOperation("中西药购销运营数据表导出")
    public void ChineseWesternMedicineReportExport(HttpServletResponse response){
        reportService.chineseWesternMedicineReportExport(response);
    }

}
